package com.lzw.d25bingso.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.lzw.d25bingso.R;
import com.lzw.d25bingso.bean.Company;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by lzw on 2017/5/17.
 */

public class CompanyAdapter extends BaseAdapter{
    private Context context;
    private List<Company> data;

    public CompanyAdapter(Context context, List<Company> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size()>0?data.size():0;
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.list_item,parent,false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
            viewHolder.tv1.setText(data.get(position).getCompany());
            viewHolder.tv2.setText("下载量:"+data.get(position).getIdownload()+"次");
            viewHolder.tv3.setText(data.get(position).getSummary());
            Picasso.with(context).load(data.get(position).getLogo()).into(viewHolder.iv);
        return convertView;
    }
    static  class  ViewHolder{
        private ImageView iv;
        private TextView tv1,tv2,tv3;
        private ImageButton ib;

        public ViewHolder(View view) {
            iv = (ImageView) view.findViewById(R.id.list_iv);
            tv1 = (TextView) view.findViewById(R.id.list_tv1);
            tv2 = (TextView) view.findViewById(R.id.list_tv2);
            tv3 = (TextView) view.findViewById(R.id.list_tv3);

        }
    }

}
